<?php
//引入StudentModel类
//require_once '../config.php';
require_once dirname(__FILE__).'/../model/StudentModel.class.php';
/*
 * 学生类控制器
 */
class StudentController{
	
	//显示已选课信息
	public function electiveCourse($studentId){
		
		//调用下层函数
		$studentModel = new StudentModel();
		$electiveCourseInfo = $studentModel->electiveCourse($studentId);
		//数据为空
		if($electiveCourseInfo == NULL){
			return false;
		}else{
			return true;
		}
	}
	
	//退选课程(根据课程编号删除选课记录)
	public function dropCourse($courseId, $studentId){
		//调用下层函数
		$studentModel = new StudentModel();
		//删除该选课信息
		$studentModel->dropCourse($courseId, $studentId);
	}
	
	//可选课程(只显示人数未满课程和学生未选课程)
	public function canSelectCourses($studentId){
		//调用model层函数
		$studentModel = new StudentModel();
		$canSelectCoursesInfo = $studentModel->canSelctCourses($studentId);
		//数据为空
		if($canSelectCoursesInfo === false){
			return false;
		} else {
			return $canSelectCoursesInfo;
		}
	}
	
	//添加选修课
	public function addElectiveCourse($studentId, $courseId){
		//调用model函数
		$studentModel = new StudentModel();
		$studentModel->addElectiveCourse($studentId, $courseId);
	}
	
}
	//退选课程
	$studentController = new StudentController();
	//获取表单参数
	$courseId = isset($_GET['courseId']) ? $_GET['courseId'] : "";
	$studentId = isset($_GET['studentId']) ? $_GET['studentId'] : "";
	//参加选课
	$select = isset($_GET['select']) ? $_GET['select'] : "";
	//echo "select = ".$select;
	//echo "******".($select === 'true')."&&&&&";
	if($courseId !== "" && $studentId !== ""){
		//$select === true(表示学生选修该课程)
		if($select === 'true'){
			//进行添加选课
			$studentController->addElectiveCourse($studentId, $courseId);
		} else{
			//退选课程(select === ""表示->退选课程)
			$studentController->dropCourse($courseId, $studentId);	
		}
		//重新加载学生界面
		header("Location:http://localhost/SelectCoursesSystem/view/student/StudentView.php");
	}else {
		//无操作
	}
	
?>

	